import Vue from "vue";
import VueRouter from "vue-router";
import KadoRouter from "./components/kado"
Vue.use(VueRouter);

export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/login/index'),
    redirect: '/kadoritu'
  },
  { path: '/Home',   component: () => import('@/views/Home'), name: 'Home'},
  {
    path: '/redirect',
    component: () => import('@/views/login/index'),
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/kadoritu',
    component: () => import('@/layout'),
    redirect: '/kadoritu/kaisya',
    alwaysShow: true, // will always show the root menu
    name: 'Kaisya',
    meta: {
      title: 'kadoritu',
      icon: 'lock',
      roles: ['ROLE_ADMIN', 'ROLE_TOUGOU'] // you can set roles in root nav
    },
    children: [
      {
        path: 'kaisya',
        component: () => import('@/views/kadoritu/kaisya'),
        name: 'kaisya',
        meta: {
          title: '会社別',
          roles: ['ROLE_ADMIN','ROLE_TOUGOU'] // or you can only set roles in sub nav
        }
      }
    ]
  },
  KadoRouter,
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }

]

const createRouter = () => new VueRouter({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-35794
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
